package scopeFunctions

/**
 *@author YanYu
 *@date 2024/12/13 13:53
 */

/**
 * let前不为null，则执行lambda表达式，
 * 返回lambda表达式的返回值
 */
fun main() {
    fun customPrint(str: String) = print(str.uppercase())

    val empty = "test".let {               // 1
        customPrint(it)                    // 2
        it.isEmpty()                       // 3
    }
    println(" is empty: $empty")

    fun printNonNull(str: String?) {
        println("Printing \"$str\":")

        str?.let {
            print("\t")
            customPrint(it)
            println()
        }
    }

    fun printIfBothNonNull(strOne: String?, strTwo: String?) {
        strOne?.let { firstString ->
            strTwo?.let { secondString ->
                customPrint("$firstString : $secondString")
                println()
            }
        }
    }

    printNonNull(null)
    printNonNull("my string")
    printIfBothNonNull("First", "Second")
}